package com.zh.controller.app;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zh.pojo.domain.PayOrder;
import com.zh.pojo.query.PageQueryWrapper;
import com.zh.result.JSONResult;
import com.zh.result.PageResult;
import com.zh.service.IPayOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

@Tag(name = "",description = "")
@RestController
@RequestMapping("/app/pay")
public class AppPayOrderController {

    @Autowired
    public IPayOrderService payOrderService;

    @Operation( summary= "微信支付",description = "微信支付")
    @Parameter(name = "orderNo",description = "订单号",required = true)
    @PostMapping("/wechatPay/{orderNo}")
    public JSONResult wechatPay(@PathVariable @Valid String  orderNo){
        return payOrderService.wechatPay(orderNo);
    }
    @Operation( summary= "微信小程序支付回调",description = "微信小程序支付回调")
    @PostMapping("/notify")
    public JSONResult wechatPayNotify(HttpServletResponse response, HttpServletRequest request){
        try {
            payOrderService.wechatPayNotify(request);
            response.setStatus(HttpServletResponse.SC_OK);
            return  JSONResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            return  JSONResult.error();
        }

    }
}
